﻿using System;
using System.Data;

using System.Web;
using System.Web.UI;
using MaLu.Framework.Common;
using MaLu.Common;
using MaLu.BusiLogic;
using Malu.Entity;
using MaLu.Data;

namespace MaluJg.web.ProcessInput
{
    [AjaxPro.AjaxNamespace("JiaDing.Platform")]
    public partial class GetStatus : ImportPage
    {


        protected void Page_Load(object sender, EventArgs e)
        {


        }

        public Const.InputDataType CurrentInputDataType
        {
            get
            {
                if (Request["InputDataType"] != null)
                {
                    return (Const.InputDataType)(Enum.Parse(typeof(Const.InputDataType), Request["InputDataType"].ToString()));
                }
                return Const.InputDataType.Employee;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            AjaxPro.Utility.RegisterTypeForAjax(typeof(GetStatus));
        }

        protected System.Data.DataTable DataGrid1_OnGetData(object sender, Wicresoft.Web.UI.WebControls.GetDataEventArgs e)
        {
            try
            {
                Wicresoft.Common.PagingEntity paging = e.Paging;

                Wicresoft.Framework.Organization.User ur = Wicresoft.Framework.Authentication.AuthenticationContext.CurrentUser;
                string uwhere = string.Empty;
                if (ur != null)
                {
                    uwhere += " and UserID='" + ur.ID + "'";

                    string WhereClause = " InputDataType='" + CurrentInputDataType.ToString() + "'" + uwhere;
                    int currentPage = DataGrid1.CurrentPageIndex;
                    int pageSize = DataGrid1.PageSize;
                    if (currentPage < 1)
                        currentPage = 1;
                    int count = 0;
                    DataTable dt = BLCommon.GetPagingList(Provider, @"*", "InputDataFileLog", WhereClause, "OpTime desc", currentPage, pageSize, false, 0, ref count);

                    e.Paging.RecordCount = count;
                    return dt;


                }
                else
                    return null;
            }
            catch (Exception exc)
            { throw exc; }
        }

        protected void DataGrid1_OnRowUpdate(object source, Wicresoft.Web.UI.WebControls.RowUpdateEventArgs e)
        {
            if (e.CommandName == "OpenLog")
            {
                try
                {
                    int id = int.Parse(e.PKs["id"].ToString());
                    InputDataFileLog log = ProviderManager.Factory.InputDataFileLog.Get(Provider, id);

                    string temp = String.Format(System.Configuration.ConfigurationManager.AppSettings["InputLog"] + "/{0}", log.logfilename);
                    Response.Write("<script>window.open('" + temp + "')</script>");
                }
                catch (Exception exc)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('" + Server.HtmlEncode(exc.Message.Replace("\"", "").Replace("'", "")) + "');</script>");
                }

            }
        }
    }
}
